/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.plaf.Style;
import com.sun.lwuit.Command;
import com.sun.lwuit.Slider;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;

/**
 *
 * @author Kvest
 */
public class ProgressForm extends Form implements ActionListener
{
    public static final int EMPTY_ID = 0;
    public static final int CANCEL_ID = 1;

    private Command cancel;
    private FormAction listener;
    
    public ProgressForm(FormAction listener)
    {
        super("");
        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        addCommandListener(this);

        addCommand(new Command("", EMPTY_ID));
        cancel= new Command("Отмена", CANCEL_ID);
        addCommand(cancel);

        final TextArea text = new TextArea("Подождите, идет обмен данными с сервером", 1, 30);
        text.setAlignment(TextArea.CENTER);
        text.setEditable(false);
        addComponent(text);

        final Slider slider = new Slider();
        slider.setFocusable(false);
        slider.setUIID("Progress");
        slider.setScrollAnimationSpeed(20);
        slider.setInfinite(true);

        Style sliderStyle = new Style(slider.getStyle());

        sliderStyle.setBorder(Border.createRoundBorder(8, 8, 0x0000ff));
        sliderStyle.setBgColor(0x999999);
        sliderStyle.setBgTransparency(255);

        slider.setUnselectedStyle(sliderStyle);

        addComponent(slider);
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.commandAction(evt.getCommand().getId());
        }
    }
}
